.class public Lcom/mime/qweibo/QHttpClient;
.super Ljava/lang/Object;
.source "QHttpClient.java"


# static fields
.field private static final CONNECTION_TIMEOUT:I = 0x4e20


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 22
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 24
    return-void
.end method


# virtual methods
.method public httpGet(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 9
    .parameter "url"
    .parameter "queryString"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 37
    const/4 v3, 0x0

    .line 39
    .local v3, responseData:Ljava/lang/String;
    if-eqz p2, :cond_0

    const-string v5, ""

    invoke-virtual {p2, v5}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v5

    if-nez v5, :cond_0

    .line 40
    new-instance v5, Ljava/lang/StringBuilder;

    invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v6

    invoke-direct {v5, v6}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v6, "?"

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    .line 43
    :cond_0
    new-instance v1, Lorg/apache/commons/httpclient/HttpClient;

    invoke-direct {v1}, Lorg/apache/commons/httpclient/HttpClient;-><init>()V

    .line 44
    .local v1, httpClient:Lorg/apache/commons/httpclient/HttpClient;
    new-instance v2, Lorg/apache/commons/httpclient/methods/GetMethod;

    invoke-direct {v2, p1}, Lorg/apache/commons/httpclient/methods/GetMethod;-><init>(Ljava/lang/String;)V

    .line 45
    .local v2, httpGet:Lorg/apache/commons/httpclient/methods/GetMethod;
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/GetMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v5

    const-string v6, "http.socket.timeout"

    .line 46
    new-instance v7, Ljava/lang/Integer;

    const/16 v8, 0x4e20

    invoke-direct {v7, v8}, Ljava/lang/Integer;-><init>(I)V

    .line 45
    invoke-virtual {v5, v6, v7}, Lorg/apache/commons/httpclient/params/HttpMethodParams;->setParameter(Ljava/lang/String;Ljava/lang/Object;)V

    .line 49
    :try_start_0
    invoke-virtual {v1, v2}, Lorg/apache/commons/httpclient/HttpClient;->executeMethod(Lorg/apache/commons/httpclient/HttpMethod;)I

    move-result v4

    .line 50
    .local v4, statusCode:I
    const/16 v5, 0xc8

    if-eq v4, v5, :cond_1

    .line 51
    sget-object v5, Ljava/lang/System;->err:Ljava/io/PrintStream;

    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "HttpGet Method failed: "

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 52
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/GetMethod;->getStatusLine()Lorg/apache/commons/httpclient/StatusLine;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    .line 51
    invoke-virtual {v5, v6}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 55
    :cond_1
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/GetMethod;->getResponseBodyAsString()Ljava/lang/String;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v3

    .line 59
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/GetMethod;->releaseConnection()V

    .line 60
    const/4 v1, 0x0

    .line 63
    return-object v3

    .line 56
    .end local v4           #statusCode:I
    :catch_0
    move-exception v0

    .line 57
    .local v0, e:Ljava/lang/Exception;
    :try_start_1
    new-instance v5, Ljava/lang/Exception;

    invoke-direct {v5, v0}, Ljava/lang/Exception;-><init>(Ljava/lang/Throwable;)V

    throw v5
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 58
    .end local v0           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v5

    .line 59
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/GetMethod;->releaseConnection()V

    .line 60
    const/4 v1, 0x0

    .line 61
    throw v5
.end method

.method public httpPost(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 9
    .parameter "url"
    .parameter "queryString"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 77
    const/4 v3, 0x0

    .line 78
    .local v3, responseData:Ljava/lang/String;
    new-instance v1, Lorg/apache/commons/httpclient/HttpClient;

    invoke-direct {v1}, Lorg/apache/commons/httpclient/HttpClient;-><init>()V

    .line 79
    .local v1, httpClient:Lorg/apache/commons/httpclient/HttpClient;
    new-instance v2, Lorg/apache/commons/httpclient/methods/PostMethod;

    invoke-direct {v2, p1}, Lorg/apache/commons/httpclient/methods/PostMethod;-><init>(Ljava/lang/String;)V

    .line 80
    .local v2, httpPost:Lorg/apache/commons/httpclient/methods/PostMethod;
    const-string v5, "Content-Type"

    .line 81
    const-string v6, "application/x-www-form-urlencoded"

    .line 80
    invoke-virtual {v2, v5, v6}, Lorg/apache/commons/httpclient/methods/PostMethod;->addParameter(Ljava/lang/String;Ljava/lang/String;)V

    .line 82
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v5

    const-string v6, "http.socket.timeout"

    .line 83
    new-instance v7, Ljava/lang/Integer;

    const/16 v8, 0x4e20

    invoke-direct {v7, v8}, Ljava/lang/Integer;-><init>(I)V

    .line 82
    invoke-virtual {v5, v6, v7}, Lorg/apache/commons/httpclient/params/HttpMethodParams;->setParameter(Ljava/lang/String;Ljava/lang/Object;)V

    .line 84
    if-eqz p2, :cond_0

    const-string v5, ""

    invoke-virtual {p2, v5}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v5

    if-nez v5, :cond_0

    .line 85
    new-instance v5, Lorg/apache/commons/httpclient/methods/ByteArrayRequestEntity;

    .line 86
    invoke-virtual {p2}, Ljava/lang/String;->getBytes()[B

    move-result-object v6

    invoke-direct {v5, v6}, Lorg/apache/commons/httpclient/methods/ByteArrayRequestEntity;-><init>([B)V

    .line 85
    invoke-virtual {v2, v5}, Lorg/apache/commons/httpclient/methods/PostMethod;->setRequestEntity(Lorg/apache/commons/httpclient/methods/RequestEntity;)V

    .line 90
    :cond_0
    :try_start_0
    invoke-virtual {v1, v2}, Lorg/apache/commons/httpclient/HttpClient;->executeMethod(Lorg/apache/commons/httpclient/HttpMethod;)I

    move-result v4

    .line 91
    .local v4, statusCode:I
    const/16 v5, 0xc8

    if-eq v4, v5, :cond_1

    .line 92
    sget-object v5, Ljava/lang/System;->err:Ljava/io/PrintStream;

    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "HttpPost Method failed: "

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 93
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->getStatusLine()Lorg/apache/commons/httpclient/StatusLine;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    .line 92
    invoke-virtual {v5, v6}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 95
    :cond_1
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->getResponseBodyAsString()Ljava/lang/String;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v3

    .line 99
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->releaseConnection()V

    .line 100
    const/4 v1, 0x0

    .line 103
    return-object v3

    .line 96
    .end local v4           #statusCode:I
    :catch_0
    move-exception v0

    .line 97
    .local v0, e:Ljava/lang/Exception;
    :try_start_1
    new-instance v5, Ljava/lang/Exception;

    invoke-direct {v5, v0}, Ljava/lang/Exception;-><init>(Ljava/lang/Throwable;)V

    throw v5
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 98
    .end local v0           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v5

    .line 99
    invoke-virtual {v2}, Lorg/apache/commons/httpclient/methods/PostMethod;->releaseConnection()V

    .line 100
    const/4 v1, 0x0

    .line 101
    throw v5
.end method

.method public httpPostWithFile(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;
    .locals 19
    .parameter "url"
    .parameter "queryString"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            "Ljava/util/List",
            "<",
            "Lcom/mime/qweibo/QParameter;",
            ">;)",
            "Ljava/lang/String;"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 121
    .local p3, files:Ljava/util/List;,"Ljava/util/List<Lcom/mime/qweibo/QParameter;>;"
    const/16 v16, 0x0

    .line 122
    .local v16, responseData:Ljava/lang/String;
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-static/range {p1 .. p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const/16 v2, 0x3f

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    move-result-object v1

    move-object/from16 v0, p2

    invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    .line 123
    new-instance v8, Lorg/apache/commons/httpclient/HttpClient;

    invoke-direct {v8}, Lorg/apache/commons/httpclient/HttpClient;-><init>()V

    .line 124
    .local v8, httpClient:Lorg/apache/commons/httpclient/HttpClient;
    new-instance v9, Lorg/apache/commons/httpclient/methods/PostMethod;

    move-object/from16 v0, p1

    invoke-direct {v9, v0}, Lorg/apache/commons/httpclient/methods/PostMethod;-><init>(Ljava/lang/String;)V

    .line 127
    .local v9, httpPost:Lorg/apache/commons/httpclient/methods/PostMethod;
    :try_start_0
    invoke-static/range {p2 .. p2}, Lcom/mime/qweibo/utils/QHttpUtil;->getQueryParameters(Ljava/lang/String;)Ljava/util/List;

    move-result-object v13

    .line 128
    .local v13, listParams:Ljava/util/List;,"Ljava/util/List<Lcom/mime/qweibo/QParameter;>;"
    invoke-interface {v13}, Ljava/util/List;->size()I

    move-result v2

    if-nez p3, :cond_1

    const/4 v1, 0x0

    :goto_0
    add-int v12, v2, v1

    .line 129
    .local v12, length:I
    new-array v15, v12, [Lorg/apache/commons/httpclient/methods/multipart/Part;

    .line 130
    .local v15, parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    const/4 v10, 0x0

    .line 131
    .local v10, i:I
    invoke-interface {v13}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    move v11, v10

    .end local v10           #i:I
    .local v11, i:I
    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-nez v2, :cond_2

    .line 135
    invoke-interface/range {p3 .. p3}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v18

    :goto_2
    invoke-interface/range {v18 .. v18}, Ljava/util/Iterator;->hasNext()Z

    move-result v1

    if-nez v1, :cond_3

    .line 141
    new-instance v1, Lorg/apache/commons/httpclient/methods/multipart/MultipartRequestEntity;

    .line 142
    invoke-virtual {v9}, Lorg/apache/commons/httpclient/methods/PostMethod;->getParams()Lorg/apache/commons/httpclient/params/HttpMethodParams;

    move-result-object v2

    invoke-direct {v1, v15, v2}, Lorg/apache/commons/httpclient/methods/multipart/MultipartRequestEntity;-><init>([Lorg/apache/commons/httpclient/methods/multipart/Part;Lorg/apache/commons/httpclient/params/HttpMethodParams;)V

    .line 141
    invoke-virtual {v9, v1}, Lorg/apache/commons/httpclient/methods/PostMethod;->setRequestEntity(Lorg/apache/commons/httpclient/methods/RequestEntity;)V

    .line 144
    invoke-virtual {v8, v9}, Lorg/apache/commons/httpclient/HttpClient;->executeMethod(Lorg/apache/commons/httpclient/HttpMethod;)I

    move-result v17

    .line 145
    .local v17, statusCode:I
    const/16 v1, 0xc8

    move/from16 v0, v17

    if-eq v0, v1, :cond_0

    .line 146
    sget-object v1, Ljava/lang/System;->err:Ljava/io/PrintStream;

    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "HttpPost Method failed: "

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    .line 147
    invoke-virtual {v9}, Lorg/apache/commons/httpclient/methods/PostMethod;->getStatusLine()Lorg/apache/commons/httpclient/StatusLine;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 146
    invoke-virtual {v1, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

    .line 149
    :cond_0
    invoke-virtual {v9}, Lorg/apache/commons/httpclient/methods/PostMethod;->getResponseBodyAsString()Ljava/lang/String;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v16

    .line 153
    invoke-virtual {v9}, Lorg/apache/commons/httpclient/methods/PostMethod;->releaseConnection()V

    .line 154
    const/4 v8, 0x0

    .line 157
    return-object v16

    .line 128
    .end local v11           #i:I
    .end local v12           #length:I
    .end local v15           #parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    .end local v17           #statusCode:I
    :cond_1
    :try_start_1
    invoke-interface/range {p3 .. p3}, Ljava/util/List;->size()I

    move-result v1

    goto :goto_0

    .line 131
    .restart local v11       #i:I
    .restart local v12       #length:I
    .restart local v15       #parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    :cond_2
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v14

    check-cast v14, Lcom/mime/qweibo/QParameter;

    .line 132
    .local v14, param:Lcom/mime/qweibo/QParameter;
    add-int/lit8 v10, v11, 0x1

    .end local v11           #i:I
    .restart local v10       #i:I
    new-instance v2, Lorg/apache/commons/httpclient/methods/multipart/StringPart;

    iget-object v3, v14, Lcom/mime/qweibo/QParameter;->mName:Ljava/lang/String;

    .line 133
    iget-object v5, v14, Lcom/mime/qweibo/QParameter;->mValue:Ljava/lang/String;

    invoke-static {v5}, Lcom/mime/qweibo/utils/QHttpUtil;->formParamDecode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    const-string v6, "UTF-8"

    invoke-direct {v2, v3, v5, v6}, Lorg/apache/commons/httpclient/methods/multipart/StringPart;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

    .line 132
    aput-object v2, v15, v11

    move v11, v10

    .end local v10           #i:I
    .restart local v11       #i:I
    goto :goto_1

    .line 135
    .end local v14           #param:Lcom/mime/qweibo/QParameter;
    :cond_3
    invoke-interface/range {v18 .. v18}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v14

    check-cast v14, Lcom/mime/qweibo/QParameter;

    .line 136
    .restart local v14       #param:Lcom/mime/qweibo/QParameter;
    new-instance v4, Ljava/io/File;

    iget-object v1, v14, Lcom/mime/qweibo/QParameter;->mValue:Ljava/lang/String;

    invoke-direct {v4, v1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 137
    .local v4, file:Ljava/io/File;
    add-int/lit8 v10, v11, 0x1

    .end local v11           #i:I
    .restart local v10       #i:I
    new-instance v1, Lorg/apache/commons/httpclient/methods/multipart/FilePart;

    iget-object v2, v14, Lcom/mime/qweibo/QParameter;->mName:Ljava/lang/String;

    invoke-virtual {v4}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v3

    .line 138
    invoke-static {v4}, Lcom/mime/qweibo/utils/QHttpUtil;->getContentType(Ljava/io/File;)Ljava/lang/String;

    move-result-object v5

    const-string v6, "UTF-8"

    invoke-direct/range {v1 .. v6}, Lorg/apache/commons/httpclient/methods/multipart/FilePart;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;)V

    .line 137
    aput-object v1, v15, v11
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    move v11, v10

    .end local v10           #i:I
    .restart local v11       #i:I
    goto :goto_2

    .line 150
    .end local v4           #file:Ljava/io/File;
    .end local v11           #i:I
    .end local v12           #length:I
    .end local v13           #listParams:Ljava/util/List;,"Ljava/util/List<Lcom/mime/qweibo/QParameter;>;"
    .end local v14           #param:Lcom/mime/qweibo/QParameter;
    .end local v15           #parts:[Lorg/apache/commons/httpclient/methods/multipart/Part;
    :catch_0
    move-exception v7

    .line 151
    .local v7, e:Ljava/lang/Exception;
    :try_start_2
    new-instance v1, Ljava/lang/Exception;

    invoke-direct {v1, v7}, Ljava/lang/Exception;-><init>(Ljava/lang/Throwable;)V

    throw v1
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 152
    .end local v7           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v1

    .line 153
    invoke-virtual {v9}, Lorg/apache/commons/httpclient/methods/PostMethod;->releaseConnection()V

    .line 154
    const/4 v8, 0x0

    .line 155
    throw v1
.end method
